#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <netdb.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <fcntl.h>



/*Semaphore's name'*/
#define KEY (666)

/*For boolean logic support*/
#define bool int
#define false 0
#define true 1

/*For array cleaning. Shortens the function - no need to pass size of array as a parameter*/
#define clearArray(X) clearVoidArray(X, sizeof(X))
/*For array copying. Shortens the function - no need to pass sizes of arrays as parameters*/
#define copyArray(X, Y) copyVoidArray(X, sizeof(X), Y, sizeof(Y))

#define SOCKET_PATH "server:3333"
#define MESSAGE_STR_SIZE 30
#define MESSAGE_INT_SIZE 6 //5 categories and one action descriptor

/*Obtain the list of available tickets*/
#define LIST_GET 1 //Client->Server: [-]
#define LIST_SEND 2 //Server->Client: [the list of available tickets]
/*Reserve the tickets*/
#define RESERVATION_DO 3 //Client->Server: [tickets to reserve]
#define RESERVATION_OK 4 //Server->Client: [-]
#define RESERVATION_FAIL 5 //Server->Client: [-]
    #define RESERVATION_FAIL_FAULT 51 //if number of of tickets to be reserved is bigger than the number of available ones
    #define RESERVATION_FAIL_BOOKED 52 //actually never happens
    #define RESERVATION_FAIL_UNSPEC 53 //nobody knows what it is...
/*Cancel the reservation*/
#define CANCEL_DO 6 //Client->Server: [-]
#define CANCEL_OK 7 //Server->Client: [-]
#define CANCEL_FAIL 8 //Server->Client: [-]
/*Buy tickets*/
#define BARGIN_DO 9 //Client->Server: [-]
#define BARGIN_OK 10 //Server->Client: [-]
#define BARGIN_FAIL 11 //Server->Client: [-]
/*End the session*/
#define EXIT 404 //end the session
    #define TIME_TO_DIE 3 //in seconds. The maximum time the process can be idle (without connection to client). After that self-termination follows.

//Reusable
void clearVoidArray(void* array, int size);
void copyVoidArray(void* from, int sizeOfFrom, void* to, int sizeOfTo);
void clearScr(); //no system("clear") here
char* itoa(int val, int base);
//Project specific
void serialize(int* data, char* target);
void deserialize(char* data, int* target);
void showTickets(int* all, int* reserved); //on server side: only for debugging

